﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace GLB.Global
{
    public static class StringExtension
    {
        //扩展方法
        //传入字节流，得到字节流。字符串（string source）转换为字节流
        public static string MD5Encrypt(this string source)
        {
            //MD5的实例 MD5.Create()  string转换为byte
            byte[] bytes = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(source));
            //因为返回string类型，byte再次转换为string
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < bytes.Length; i++)
            {
                builder.Append(bytes[i].ToString("x2"));
            }
            return builder.ToString();

        }
    }
}
